var ImgButton = function () {
  var template = /* html */ `
    <el-popover v-model="visible" placement="bottom" trigger="click" :width="popoverWidth" :popper-class="popperClass">
      <el-button :size="size" :type="type" slot="reference">{{buttonText}}</el-button>
      <template v-if="limit===1">
        <div v-if="readonly&&img===''" style="text-align:center">暂无图片</div>
        <img-upload v-else v-model="img" :readonly="readonly" @input="imgChange" :img-width="imgWidth"
          :img-height="imgHeight" :img-handle="imgHandle"></img-upload>
      </template>
      <template v-else>
        <div v-if="readonly&&img.length===0" style="text-align:center">暂无图片</div>
        <imgs-upload v-else v-model="img" :readonly="readonly" :limit="limit" @input="imgChange" :img-width="imgWidth"
          :img-height="imgHeight" :img-handle="imgHandle" :readonly-img="readonlyImg"></imgs-upload>
      </template>
    </el-popover>
  `;

  return {
    props: {
      value: {
        type: [Array, String],
        required: true
      },
      buttonText: {
        type: String,
        default: '图片'
      },
      readonlyImg:Array,
      limit: Number,
      imgWidth: [String, Number],
      imgHeight: [String, Number],
      imgHandle: Array,
      popoverWidth: [String, Number],
      popperClass:String,
      size: String,
      type: String,
      readonly: Boolean
    },

    watch: {
      value: function () {
        var inputValue = this.inputValue;
        if (inputValue !== null) {
          this.inputValue = null;
          return;
        }
        this.img = this.value;
      }
    },

    data: function () {
      return {
        visible: false,
        img: this.value,
        inputValue: null
      }
    },

    methods: {
      imgChange: function () {
        var img = this.img;
        this.inputValue = img;
        this.$emit('input', img);
      }
    },

    components: {
      ImgUpload: ImgUpload,
      ImgsUpload: ImgsUpload
    },

    template: template
  };
}();
